package lattice.traveler;

import java.util.StringTokenizer;


public class VectorClock {
	final int[] clocks_;
	
	public VectorClock(int size) {
		clocks_ = new int[size];
		for (int i = 0; i < size; ++i) clocks_[i] = 0;
	}
	
	public VectorClock(int size, String stamp) {
		this(size);
		set(stamp);
	}
	
	public int get(int pid) {
		return clocks_[pid];
	}
	
	public void set(String stamp) {
		StringTokenizer stampTokens = new StringTokenizer(stamp,",");
		
		while (stampTokens.hasMoreTokens()) {
			String token = stampTokens.nextToken();
			StringTokenizer tokenValues = new StringTokenizer(token,"/");
			while (tokenValues.hasMoreTokens()) {
				int ID = Integer.parseInt(tokenValues.nextToken()) - 1;
				int value = Integer.parseInt(tokenValues.nextToken());
				clocks_[ID] = value;
			}
		}
	}
}

